package com.ruoyi.web.controller.cashier;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.MemberRechargeRecords;
import com.ruoyi.system.service.MemberRechargeRecordsService;
import com.ruoyi.system.util.AbdulEmptyUtils;
import com.ruoyi.system.util.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/recharge")
@Api(tags = "会员充值记录管理")
public class MemberRechargeRecordsController extends BaseController {

    @Autowired
    private MemberRechargeRecordsService rechargeRecordsService;

    @PostMapping("/page")
    @ApiOperation("获取所有充值记录")
    public BaseResponse<IPage<MemberRechargeRecords>> page(MemberRechargeRecords memberRechargeRecords) {
        LambdaQueryWrapper<MemberRechargeRecords> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getMemberId()), MemberRechargeRecords::getMemberId, memberRechargeRecords.getMemberId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getCardNumber()), MemberRechargeRecords::getCardNumber, memberRechargeRecords.getCardNumber());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getStatus()), MemberRechargeRecords::getStatus, memberRechargeRecords.getStatus());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getOrderType()), MemberRechargeRecords::getOrderType, memberRechargeRecords.getOrderType());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getStoreId()), MemberRechargeRecords::getStoreId, memberRechargeRecords.getStoreId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberRechargeRecords.getPaymentMethod()), MemberRechargeRecords::getPaymentMethod, memberRechargeRecords.getPaymentMethod());
        wrapper.orderByDesc(MemberRechargeRecords::getCreateTime);
        IPage<MemberRechargeRecords> page = new Page<>(memberRechargeRecords.getPageNum(), memberRechargeRecords.getPageSize());
        IPage<MemberRechargeRecords> recordsIPage = rechargeRecordsService.page(page, wrapper);
        return BaseResponse.success(recordsIPage);
    }

}
